package tech.veedo.munchkin.controllers.frontend;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tech.veedo.munchkin.beans.basic.User;
import tech.veedo.munchkin.beans.frontend.Form;
import tech.veedo.munchkin.beans.frontend.QueryParams;
import tech.veedo.munchkin.beans.frontend.process.NodePassing;
import tech.veedo.munchkin.constants.Operation;
import tech.veedo.munchkin.services.frontend.MainService;
import tech.veedo.munchkin.verifications.frontend.FormVerify;

@RestController
@RequestMapping("/munc/p")
@Api(tags = "2-前台-1-主体流程接口集合")
public class MainController {

    @Autowired
    private FormVerify formVerify;

    @Autowired
    private MainService mainService;

    @ApiOperation("提交审批")
    @PostMapping("/{workflowId}/{orgCode}/submit")
    public boolean submit(@PathVariable Long workflowId,
                          @PathVariable String orgCode,
                          Form form) {
        formVerify.verify(Operation.ADD, form);
        return mainService.submit(workflowId, orgCode, form, User.defaultU());
    }

    @ApiOperation("可审批项列表查询")
    @PostMapping("/page")
    public Page<NodePassing> page(@RequestBody QueryParams<NodePassing> params) {
        return mainService.page(params, User.defaultU());
    }

    @ApiOperation("审批通过")
    @PostMapping("/yes/{alwaysYes}")
    public boolean yes(@RequestBody NodePassing nodePassing, @PathVariable boolean alwaysYes) {
        // 查询节点所在工作流是否后台正在编辑，是-退出，否-继续
        // code here...
        // 查询节点记录状态是否发生变化，是-退出，否-继续
        // code here...
        // 查询当前登录人员是否节点审核人，是-继续，否-退出
        return mainService.yes(nodePassing, alwaysYes, User.defaultU());
    }

}
